package com.monkey.web.dto.request.user;

import com.monkey.core.domain.user.User;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.NotEmpty;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;

/**
 * Created by silentwu on 2015/7/3.
 */
public class AddUserDto {

    @NotEmpty(message = "{account.not.null}")
    @Pattern(regexp = User.ACCOUNT_PATTERN, message = "{user.account.not.valid}")
    @Length(min = User.ACCOUNT_MIN_LENGTH, max = User.ACCOUNT_MAX_LENGTH, message = "{user.account.not.valid}")
    private String account;

    @NotEmpty(message = "{password.not.null}")
    @Length(min = User.PASSWORD_MIN_LENGTH, max = User.PASSWORD_MAX_LENGTH, message = "{user.password.not.valid}")
    private String password;

    @NotEmpty(message = "{nick.not.null}")
    @Length(min = User.NICK_MIN_LENGTH, max = User.NICK_MAX_LENGTH, message = "{user.nick.not.valid}")
    private String nick;

    @NotEmpty(message = "{email.not.null}")
    @Pattern(regexp = User.EMAIL_PATTERN, message = "{user.email.not.valid}")
    private String email;

    @NotEmpty(message = "{mobile.not.null}")
    @Pattern(regexp = User.MOBILE_PATTERN, message = "{user.mobile.not.valid}")
    private String mobile;

    @NotNull(message = "{organization.not.null}")
    private Long organizationId;

    public AddUserDto() {
    }

    //===============================================================

    public User toAccount() {
        User user = new User();
        user.setAccount(this.account);
        user.setNick(this.nick);
        user.setEmail(this.email);
        user.setMobile(this.mobile);
        user.setPassword(this.password);
        return user;
    }

    public Long getOrganizationId() {
        return organizationId;
    }

    public void setOrganizationId(Long organizationId) {
        this.organizationId = organizationId;
    }

//===============================================================


    public String getAccount() {
        return account;
    }

    public void setAccount(String account) {
        this.account = account;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getNick() {
        return nick;
    }

    public void setNick(String nick) {
        this.nick = nick;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getMobile() {
        return mobile;
    }

    public void setMobile(String mobile) {
        this.mobile = mobile;
    }

}
